<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>营销模板 列表</title>
<jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="clearFix"></div>
	            <div class="btnsBox formBtns notRight">
					<span id="addBtn" onclick="addBtn();" class="sq-button-round">新增</span>
				</div>
        	</div>
        </form>
    </div>
</div>
<div id="mcrGridId" class="sq-grid"></div>
</div>

<script type="text/javascript">
	var grid = null;
	$(function () {
	    initForm();
		initGrid();
	});

	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询按钮事件
	function searchBtn(){
		 var form = new liger.get("searchBar");
		 var data = form.getData();
		 for (name in data){
			grid.setParm(name,data[name]);
		 };
		grid.reload();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#mcrGridId").ligerGrid({
	    	url: '<%=path%>/mcr/mcrMarketTemplet/initList.do',
	    	method : 'post',
	    	isSingleCheck: false,
	    	parms:getSearchParams(),
	        columns: [
				{ display: '描述', name: 'content', width: 150, enabledSort:true},
                { display: '模板类型', name: 'tempType', width: 80, enabledSort:true,
                    render:function(rowData){
                        if(rowData.tempType=="1"){
                            return "微信";
                        }
                    }
                },
	            { display: '顶部图片', name: 'topImgPath', width: 200, enabledSort:true,
                    render:function(rowData){
                        if(rowData.topImgPath != null){
                            return "<a href=\"javascript:openImg111('"+rowData.topImgPath+"','上部图片')\">"+rowData.topImgPath+"</a>";
                        }
                    }
                },
	            { display: '中部图片', name: 'midImgPath', width: 200, enabledSort:true,
                    render:function(rowData){
                        if(rowData.midImgPath != null){
                            return "<a href=\"javascript:openImg111('"+rowData.midImgPath+"','中部图片')\">"+rowData.midImgPath+"</a>";
                        }
                    }
                },
	            { display: '底部图片', name: 'botImgPath', width: 200, enabledSort:true,
                    render:function(rowData){
                        if(rowData.botImgPath != null){
                            return "<a href=\"javascript:openImg111('"+rowData.botImgPath+"','底部图片')\">"+rowData.botImgPath+"</a>";
                        }
                    }
                },
	            { display: '背景色', name: 'background', width: 50, enabledSort:true  ,
                    render:function(rowData){
                        return "<input type=\"color\" value=\""+rowData.background+"\" disabled >";
                    }
                },
                { display: '背景色值', name: 'background', width: 80, enabledSort:true},
                { display: '是否启用', name: 'isValid', width: 80, enabledSort:true,
                    render:function(rowData){
                        if(rowData.isValid=="0"){
                            return "未启用";
                        }else{
                            return "启用";
                        }
                    }
                },
                { display: '修改时间', name: 'mdfTm', width: 150, enabledSort:true, render:renderDate},
	            { display: '创建时间', name: 'crtTm', width: 150, enabledSort:true, render:renderDate},
	            getGridOperColumnContent()
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
            // rowHeight:50,
	        rownumbers:true
	    });
	    grid = liger.get("mcrGridId");
	    grid.setHeight(400);
	}

	//Grid操作列
	function getGridOperColumnContent(){
		var data = {
			display: '操作',
			isSort: false,
			width: 280,
			render: function (rowdata, rowindex, value){

				var h='<a class="sq-button-hasicon" href="javascript:modifyRow(';
				h+="'"+rowdata.id+"'";
				h+=",'mid_man_grid_id'"
				h+=")\"><i class=\"sqBtnIco_4\"></i>修改</a>"

				var z='<a class="sq-button-hasicon" href="javascript:isValid(';
				z+="'"+rowdata.id+"',";
				z+="'"+'1'+"'";
				z+=",'mid_man_grid_id'"
				z+=")\"><i class=\"sqBtnIco_7\"></i>启用</a>"

				var y='<a class="sq-button-hasicon" href="javascript:isValid(';
				y+="'"+rowdata.id+"',";
				y+="'"+'0'+"'";
				y+=",'mid_man_grid_id'"
				y+=")\"><i class=\"sqBtnIco_7\"></i>禁用</a>"

				var returnStr = h;
				if(rowdata.isValid == 0){
					returnStr = z + h;
				}else{
					returnStr = y + h;
				}
				return returnStr;
			}
		}
		return data;
	}

	//删除回调
	function delCallback(msg){
		if(msg.success == 1){
			UIUtils.alertSuccess(msg.info);
			grid.reload();
		}else{
			UIUtils.alertError(msg.info);
		}
	}

	//启用禁用数据
	function isValid(_id,isValid){
		$.ligerDialog.confirm('确定执行该操作吗?', function (flag) {
			if(flag == false)return;
			var url = '<%=path%>/mcr/mcrMarketTemplet/switch.do';
			AjaxUtils.ajaxPost(url, {id:_id,isValid:isValid}, delCallback);
		});
	}

	//修改方法
	function modifyRow(_id){
		$.ligerDialog.SQopen({
			width: 800,
			height:400,
			title : '修改',
			url:'<%=path%>/mcr/mcrMarketTemplet/toAddPage.do?id='+_id,
			// 自定义buttons的时候 不要设置 fixButtons: true
			buttons: [{
				text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
				onclick: function (item, Dialog) {
					//在子页面里绑定 frameElement.dialog.onOk = function () {}
					if (Dialog.onOk) {
						Dialog.onOk();
					}
				}
			}, {
				text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
				onclick: function (item, Dialog) {
					//在子页面里绑定 frameElement.dialog.onCancel = function () {}
					if (Dialog.onCancel) Dialog.onCancel();
				}
			}
			]
		});
	}

	//新增
	function addBtn(){
		$.ligerDialog.SQopen({
			width: 800,
			height:400,
			title : '新增',
			url:'<%=path%>/mcr/mcrMarketTemplet/toAddPage.do',
			// 自定义buttons的时候 不要设置 fixButtons: true
			buttons: [{
				text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
				onclick: function (item, Dialog) {
					//在子页面里绑定 frameElement.dialog.onOk = function () {}
					if (Dialog.onOk) {
						Dialog.onOk();
					}
				}
			}, {
				text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
				onclick: function (item, Dialog) {
					//在子页面里绑定 frameElement.dialog.onCancel = function () {}
					if (Dialog.onCancel) {
						Dialog.onCancel()
					};
				}
			}
			]
		});
	}

    // 获取身份证照片信息
    function openImg111(path, fileName) {
        if (SQ.regs.img.test(fileName)) {
            window.__ImgSrc = path;
            window.__ImgTit = fileName;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        } else {
            window.open(path);
        }
    }

	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}

</script>

</body>
</html>